{
LANG : PASCAL
PROB : milk2
}

program MILK2;
const
  fi = 'milk2.in';
  fo = 'milk2.out';
  max = 5000;
type
  dur = record
          s, f : longint;
        end;
var
  a : array[1..max] of dur;
  n, idle, milk : longint;

procedure inp;
var
  i : longint;
begin
  read(n);
  for i := 1 to n do
    with a[i] do read(s, f);
end;

procedure swap(i, j : longint);
var
  temp : dur;
begin
  temp := a[i];
  a[i] := a[j];
  a[j] := temp;
end;

procedure sort(l, r : longint);
var
  i, j, k : longint;
begin
  if l >= r then exit;
  i := l;
  j := r;
  k := a[l + random(r-l+1)].s;
  repeat
    while a[i].s < k do inc(i);
    while k < a[j].s do dec(j);
    if i <= j then
    begin
      swap(i, j);
      inc(i); dec(j);
    end;
  until i > j;
  sort(i, r); sort(l, j);
end;

procedure init;
begin
  sort(1, n);
  milk := 0;
  idle := 0;
end;

procedure process;
var
  i, j : longint;
  left, right : longint;
begin
  left := a[1].s;
  right := a[1].s;
  for i := 1 to n do
    if a[i].s <= right then
    begin
      if right < a[i].f then right := a[i].f;
      if milk < right - left then milk := right - left;
    end
    else
    begin
      if idle < a[i].s - right then idle := a[i].s - right;
      left := a[i].s;
      right := a[i].f;
    end;
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  inp;
  init;
  process;
  writeln(milk, ' ', idle);
  close(output);
  close(input);
end.